<?php
/*
 * @category   Zend_extension
 * @package    Zend_View
 * @subpackage Helper
*/


require_once 'Zend/View/Helper/Abstract.php';

require_once('phpLoader/phploader/loader.php');

class Myzen_View_Helper_YUILoader extends Zend_View_Helper_Abstract {
	
	protected $_loader;
	protected $_yuiVersion = '2.8.0r4';
	protected $_useYUICDN = false;
	protected $_debug = true;
		
    public function __construct()
    {
    	$this->_loader = new YAHOO_util_Loader($this->_yuiVersion);
    	$this->_loader->loadSingle('logger');
    	
    	if($this->_debug) $this->_loader->filter = YUI_DEBUG;
    	//$this->_loader->base = '/draftrack/FE/public/ressources/javascript/yui/'.$this->_yuiVersion.'/build/';
    }
  

    public function YUILoader()
    {
       return $this;
    }
    

    /**
     * Save the message in the placeholder
     * 
     * @param  array $list array containing all the YUI modules that need to be loaded 
     * @return string
     */    
    public function load($list = array()) {
    	$string = '';
    	if(!empty($list)) {
    		foreach($list as $module) $this->_loader->loadSingle($module);
    	}
    }
    
    
    /**
     * Create string representation of placeholder
     * only one message is returned, last error take precedence over last warning that takes precedence over cconfirmation
     * 
     * @param  void
     * @return string  html code that will be displayed, void if no message to return
     */
    public function __toString()
    {
    	if(!$this->_useYUICDN) $this->_loader->base = $this->view->baseUrl().'/ressources/javascript/yui/'.$this->_yuiVersion.'/build/';
    	
		return '<!-- YUILoader helper loaded modules -->'."\n".$this->_loader->tags().'<!-- end YUILoader helper loaded modules -->'."\n";
    }

}

?>